package com.merlin.demo_wellshape.controller;

import com.merlin.demo_wellshape.pojo.DailyQuote;
import com.merlin.demo_wellshape.pojo.ResponseMessage;
import com.merlin.demo_wellshape.service.DailyQuoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("/api")
public class DailyQuoteController {
    @Autowired
    private DailyQuoteService dailyQuoteService;

    // 获取随机鸡汤
    @GetMapping("/daily-quote") // URL：localhost:8080/api/daily-quote  method:get
    public ResponseMessage<String> getRandomQuote() {
        Optional<DailyQuote> quote = dailyQuoteService.getRandomQuote();
        if (quote.isPresent()) {
            return ResponseMessage.success(quote.get().getQuote());
        } else {
            return new ResponseMessage<>(500, "获取鸡汤失败", null);
        }
    }
}
